package com.linchong.concurrency.singleton;

import com.linchong.concurrency.annoations.Recommend;
import com.linchong.concurrency.annoations.ThreadSafe;

/**
 * @author linchong
 * @version 1.0
 * @Date: 2020-12-08 17:55
 * @Description: SingletonExample7$
 * 枚举模式，最安全
 */
@ThreadSafe
@Recommend
public class SingletonExample7 {
	/**
	 * 私有化构造
	 */
	private SingletonExample7(){

	}

	public static SingletonExample7 getInstance(){
		return Singleton.INSTANCE.getInstance();
	}

	private enum Singleton{
		/**
		 * 实例
		 */
		INSTANCE;
		private SingletonExample7 singleton;

		/**
		 * JVM保证这个方法绝对被调用一次
		 */
		Singleton(){
			singleton = new SingletonExample7();
		}

		public SingletonExample7 getInstance(){
			return singleton;
		}
	}
}
